﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using eStream.Helpdesk.Notifier.Properties;
using System.ComponentModel;

namespace eStream.Helpdesk.Notifier
{
    public class NotifierSettings : INotifyPropertyChanged
    {
        public long? LastCommentID
        {
            get
            {
                if (Settings.Default.LastCommentID > -1L)
                    return Settings.Default.LastCommentID;
                return null;
            }
            set
            {
                if (!value.HasValue)
                    Settings.Default.LastCommentID = -1L;
                else
                    Settings.Default.LastCommentID = value.Value;
            }
        }

        public bool LastAttemptSuccessfull
        {
            get 
            {
                return Settings.Default.LastAttemptSuccessfull;
            }
            set
            {
                Settings.Default.LastAttemptSuccessfull = value;
            }
        }

        public string HelpdeskAddress
        {
            get
            {
                return Settings.Default.HelpdeskAddress;
            }
            set
            {
                Settings.Default.HelpdeskAddress = value.Trim();
                NotifyPropertyChanged("HelpdeskAddress");
            }
        }

        public string Email
        {
            get
            {
                return Settings.Default.Email;
            }
            set
            {
                Settings.Default.Email = value.Trim();
                NotifyPropertyChanged("Email");
            }
        }

        public string Password
        {
            get
            {
                return Settings.Default.Password;
            }
            set
            {
                Settings.Default.Password = value.Trim();
                NotifyPropertyChanged("Password");
            }
        }

        public void Save()
        {
            Settings.Default.Save();
        }

        public event PropertyChangedEventHandler PropertyChanged;
        public void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
